package 全排列;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Solution1 {
    List<List<Integer>> res = new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        LinkedList<Integer> track =  new LinkedList<>();
        backtrack(nums,track);
        return res;
    }

    public void backtrack(int[] nums,List<Integer> track ){
        if(nums.length == track.size()){
            res.add(new LinkedList<>(track));
        }

        for(int i = 0 ; i < nums.length ; i++){
            if(track.contains(nums[i])){
                continue;
            }
            track.add(nums[i]);
            backtrack(nums,track);
            track.remove(track.size()-1);
        }
    }
}
